package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayUserVocSentenceDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocExampleSentenceCommand;
import com.cskaoyan.wordmemorize.service.UserPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/priviledge/voc")
public class UserPrivilegeServiceController {
    @Autowired
    UserPrivilegeService userPrivilegeService;
    @PostMapping("example")
    public Result<Object> addVocSentence(@RequestBody UserVocExampleSentenceCommand  command){
        Long userId = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.addUserVocSentence(command,userId);
        return Result.ok();
    }
    @PutMapping("example")
    public Result<Object> updateVocSentence(@RequestBody UserVocExampleSentenceCommand command){
        Long userId = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.updateUserVocSentence(command,userId);
        return Result.ok();
    }
    @GetMapping("example/list")
    public Result<PageDTO<DisplayUserVocSentenceDTO>> getVocSentenceList(PageRequest pageRequest){
        Long userId = StpKit.USER.getLoginIdAsLong();
        PageDTO<DisplayUserVocSentenceDTO> pageDTO = userPrivilegeService.getUserVocSentence(pageRequest,userId);
        return Result.ok(pageDTO);
    }
}
